<?php

namespace App\Models;


class ConfigModel
{
    /**
     * 获取单项配置
     * entry conn ConfigExample
     * return array
     * */
      public static function getConfigSingle($conn,$name){
            $querySql="select `id`,`name`,`val`,`company`,`status`,`time`,`remarks`,`type` from `config` where `name` = '$name'";
            return $conn->readConn($querySql);
      }
    /**
     * 获取单项配置(name)
     * entry conn ConfigExample
     * return array
     * */
    public static function getConfigSingleValName($conn,$name){
        $querySql="select `val` from `config` where `name` = '$name'";
        $readConn = $conn->readConn($querySql);
        return $readConn["val"];
    }

    /**
     * 修改配置可添加字段
     * entry ConfigExample
     * return int
     * */
    public static function upConfigInside($conn,$ConfigExample){
        $joinSql="";
        if($ConfigExample->val !=null){
            $joinSql.=" `val` = '$ConfigExample->val',";
        }
        if($ConfigExample->company !=null){
            $joinSql.=" `company` = '$ConfigExample->company',";
        }
        if($ConfigExample->status !=null){
            $joinSql.=" `status` = '$ConfigExample->status',";
        }
        if($ConfigExample->remarks !=null){
            $joinSql.=" `remarks` = '$ConfigExample->remarks',";
        }
        if($ConfigExample->type !=null){
            $joinSql.=" `type` = '$ConfigExample->type',";
        }
        if($joinSql !=null){
            $innerJoin = rtrim($joinSql,",");
            $upUserSql="UPDATE  `config` SET $innerJoin WHERE `id` = '$ConfigExample->id' and `name` = '$ConfigExample->name' ";
            return $conn->executeConn($upUserSql);
        }
    }
}